package org.example.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.bean.EmailBean;
import org.example.mapper.IEmailMapper;
import org.example.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Arrays;

@Service
@Transactional
public class EmailServiceImp implements IEmailService {
    @Autowired
    private IEmailMapper mapper;
    @Override
    public void add(EmailBean emailBean, String[] staffNameArray, int[] staffIDArray) {
        String str = Arrays.toString(staffNameArray);
        String nameStr = str.substring(1,str.length()-1);
        emailBean.setAcceptNames(nameStr);
        mapper.add(emailBean);
        mapper.addInBox(emailBean.getId(),staffIDArray);
    }

    @Override
    public PageInfo<EmailBean> cutFindSendByItem(Integer pageNum, Integer sendID, String title, LocalDate starDate, LocalDate endDate) {
        PageHelper.startPage(pageNum,2);
        PageInfo pageInfo = PageInfo.of(mapper.cutFindSendByItem(sendID,title,starDate,endDate));
        return pageInfo;
    }

    @Override
    public EmailBean findByID(Integer emailID) {
        return mapper.findByID(emailID);
    }

    @Override
    public void del(Integer emailID) {
        mapper.del(emailID);
    }
}
